﻿#!/usr/bin/env python
#coding:utf-8
#Code by Mango



from socket import *
from geColor import *
from os import listdir,getcwd
import urllib
import urllib2
import cookielib
import re,sys,hashlib
import threading
import thread
import time
import paramiko

class fuck:
    ''' all plugins function :) 所有的插件函数'''
    def checkport(self,host,port):
        '''check host's port !open?::return 1 or 0 端口扫描'''
        try:
            s=socket(AF_INET,SOCK_STREAM)
            s.settimeout(5)
            s.connect((host,int(port)))
            s.close()
            return 1
        except:
            return 0

    def urlget(self,url):
        '''url open=>get get方式'''
        return urllib.urlopen(url)

    def urlpost(self,url,value):
        '''url post post方式'''
        data    = urllib.urlencode(value) #提交表单
        headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' }  #自定义http头
        res     = urllib2.Request(url,data,headers) #urllib2.Request发送请求(url,表单,http头)
        try:
            ok  = urllib2.urlopen(res)
            return ok
        except:
            return 0

    def urlupload(self,url,value):
        '''url upload file 上传文件'''
        cookies = cookielib.CookieJar()
        opener  = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),
                                MultipartPostHandler.MultipartPostHandler)
        opener.open(url, value)

    def urltoip(self,url):
        '''url to ip 域名转ip'''
        return gethostbyname(url)

    def writelog(self,logname,log):
        '''write log to file 写日志文件'''
        fp = open('output/%s.log'%logname,'a')
        fp.write(log)
        fp.close()

    def find(self,r,t):
        '''re find 正则'''
        return re.findall(r,t)

    def ssh_command(self, a, b, c, d, e):
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(a, b, c, d)    # 'ip' port 'user' 'passwd'
        stdin, stdout, stderr = ssh.exec_command(e)
        out = stdout.readlines()   # list
        return out
        ssh.close()


if __name__ == '__main__':
    print __doc__
